<%--
  Created by IntelliJ IDEA.
  User: 17534
  Date: 2020/9/14
  Time: 21:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>查询页面</title>
</head>
<script src="js/jquery-3.5.0.min.js"></script>
<body>
<h1>记账管理</h1>
<p>
<form action="/getallbills" method="post">
    类型：
    <select name="typeid">
        <option value="-1">不限</option>
        <c:forEach items="${billtypes}" var="type">
            <option value="${type.id}" ${tid==type.id?'selected':''}>${type.bname}</option>
        </c:forEach>
    </select>
    时间：
    从<input type="text" name="begin" value="${begintime}">到<input type="text" name="end" value="${endtime}">
    <input id="find" type="submit" value="搜索">
</form>
    <input type="button" value="记账" onclick="javascript:location.href='/getbillstype'">
</p>
<table border="1" width="500">
    <tr>
        <td>标题</td>
        <td>时间</td>
        <td>类别</td>
        <td>金额</td>
        <td>说明</td>
        <td>操作</td>
    </tr>
    <c:if test="${info.list.size()>=0}">
        <c:forEach items="${info.list}" var="bill">
            <tr>
                <td>${bill.title}</td>
                <td><fmt:formatDate value="${bill.bilitime}" pattern="yy-MM-dd"></fmt:formatDate></td>
                <td>${bill.billtype.bname}</td>
                <td>
                    <c:choose>
                        <c:when test="${bill.typeid=='1'||bill.typeid=='2'||bill.typeid=='3'}">
                            -${bill.price}
                        </c:when>
                        <c:when test="${bill.typeid=='4'||bill.typeid=='5'||bill.typeid=='6'}">
                            +${bill.price}
                        </c:when>
                        <c:otherwise>
                            ${bill.price}
                        </c:otherwise>
                    </c:choose>
                </td>
                <td>${bill.explains}</td>
                <td>
                    <a href="/deletebyid?bid=${bill.id}">删除</a>
                    <a href="/findbyid?bid=${bill.id}">修改</a>
                </td>
            </tr>
        </c:forEach>
    </c:if>
    <c:if test="${info.list.size()==0}">
        <tr>
            <td colspan="6">
                <h3>没有找到任何数据！</h3>
            </td>
        </tr>
    </c:if>
    <tr>
        <td colspan="6">
            <a href="/getallbills?typeid=${tid}&begin=${begintime}&end=${endtime}">首页</a>
            <a href="/getallbills?index=${info.prePage==0?1:info.prePage}&typeid=${tid}&begin=${begintime}&end=${endtime}">上一页</a>
            <a href="/getallbills?index=${info.nextPage==0?info.pages:info.nextPage}&typeid=${tid}&begin=${begintime}&end=${endtime}">下一页</a>
            <a href="/getallbills?index=${info.pages}&typeid=${tid}&begin=${begintime}&end=${endtime}">尾页</a>
            第${info.pageNum}页
            总页数：${info.pages}
            总条数：${info.total}
        </td>
    </tr>
</table>
</body>
<script>
    $.post("/gettypes",null,function (result) {
        console.log("成功！");
    });
</script>
</html>
